package com.zhelun.demo;

import android.support.annotation.NonNull;

import demo.bocweb.com.sdk.util.ToastUtils;
import io.reactivex.functions.Consumer;

/**
 * Created by zhelun on 2018/1/18.
 */

public class TopMoviePresenter extends MovieTop250Contract.TopMoviePresenter {
    @NonNull
    public static TopMoviePresenter newInstance() {
        return new TopMoviePresenter();
    }

    @Override
    public void getTopMovieList(int start, int count) {
        if (mIModel == null || mIView == null) {
            return;
        }
        mRxManager.register(mIModel.getTopMovieList(start, count)
                .subscribe(new Consumer<HotMovieBean>() {
                    @Override
                    public void accept(HotMovieBean hotMovieBean) throws Exception {
                        if (mIView == null)
                            return;
                        mIView.updateTopMovieList(hotMovieBean.getSubjects());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        if (mIView == null)
                            return;
                        ToastUtils.showToast("网络异常");
                    }
                })
        );
    }

    @Override
    public MovieTop250Model getModel() {
        return MovieTop250Model.newInstance();
    }

    @Override
    public void onStart() {

    }


}
